#include <Python.h>
#include <iostream>
#include <chrono>


using namespace std;

int main(){
	Py_SetPythonHome(L"/home/st/ubuntu_data/software/miniconda3/envs/ciassd_tra_pre"); //virtual enviroment path setting, otherwise don't work
	Py_Initialize(); //使用python前要调用此函数，进行初始化,开启虚拟机
	if( !Py_IsInitialized()){
		cout << "python init fail" << endl;
		return 0;
	}

	PyRun_SimpleString("import sys");
	PyRun_SimpleString("sys.path.append('/home/st/ubuntu_data/NRSL/little_project/cpp_learning/parallel_test/script')");

	PyObject* pModule = PyImport_ImportModule("parall_test");
	if( pModule == NULL ){
		cout <<"module not found" << endl;
		return 1;
	}

 	PyObject* pFunc1 = PyObject_GetAttrString(pModule, "func1");
	 PyObject* pFunc2 = PyObject_GetAttrString(pModule, "func2");
    if( !pFunc1 || !PyCallable_Check(pFunc1)){
        cout <<"not found function add_num" << endl;
        return 0;
    }

	std::chrono::system_clock::time_point t1, t2;
	t1 = std::chrono::system_clock::now();
    PyObject_CallObject(pFunc1, NULL );
	PyObject_CallObject(pFunc2, NULL );
	t2 = std::chrono::system_clock::now();
	cout<<std::chrono::duration_cast<std::chrono::microseconds>( t2-t1 ).count()<<std::endl;

    Py_Finalize();

	return 0;
}
